/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.OutBillItemDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import com.minierp.helper.PageHelper;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

public class OutBillItemDaoImpl extends BaseDaoImpl implements OutBillItemDao {
	public List getList(long billId) {
		String sql = "from com.minierp.model.OutBillItem s where s.billId="
				+ billId + " order by s.id";
		return this.getHibernateTemplate().find(sql);
	}

	public int delete(final long id) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.OutBillItem where id=:id";
						return new Integer(session.createQuery(hql)
								.setLong("id", id).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}

	public List getMultiPrintList(String[] idArr) {
		String idStr = PageHelper.createIdArrStr(idArr, "b.id", true);
		String sql = "select p.product_code,p.product_name,p.unit,i.amount,0 as unit_price,i.cost,i.mark,b.bill_code,b.business_bill_code,b.examined,s.amount as st_amount,s.cost as st_cost from out_bill_item i left join product p on i.product_id=p.id left join out_bill b on b.id=i.bill_id left join stock s on s.storehouse_id=b.storehouse_id and s.product_id=i.product_id where 1=1"
				+ idStr + " order by b.id,i.id";
		Session sess = null;

		List arg6;
		try {
			sess = this.getSession();
			SQLQuery q = sess.createSQLQuery(sql);
			arg6 = q.list();
		} finally {
			if (sess != null) {
				this.releaseSession(sess);
			}

		}

		return arg6;
	}
}